import { createStore } from "./core/state-manager";

const routerConfig = [
  { name: "home", path: "/" },
  { name: "home", path: "/home" },
  { name: "market", path: "/market" },
  { name: "cart", path: "/cart" },
  { name: "my-orders", path: "/my-orders" },
  { name: "knowledge", path: "/knowledge" },
  { name: "community", path: "/community" },
  { name: "farmer-orders", path: "/farmer-orders" },
  { name: "farmer-products", path: "/farmer-products" },
  { name: "admin-products", path: "/admin-products" },
  { name: "admin-orders", path: "/admin-orders" },
  { name: "video", path: "/video" },
  { name: "user", path: "/user/:id" },
  { name: "product-detail", path: "/product-detail" },
  { name: "check-out", path: "/check-out" },
  { name: "post-detail", path: "/post-detail" },
];

// 初始路由状态
const initialState = {
  currentPath: "/",
  currentName: "Home",
  config: routerConfig,
};

// 调试中间件
const loggerMiddleware = (store) => (next) => (updater) => {
  console.log("Before state:", store.getState());
  const result = next(updater);
  console.log("After state:", store.getState());
  return result;
};

export const routerStore = createStore(initialState, [loggerMiddleware]);
